<?php

namespace App\Models;

use App\Observers\LogObserver;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;

class Log extends Model
{

    protected $table = 'log';
    protected $primarykey = 'id';
    public $timestamps = false;
    protected $casts = [
        'remember' => 'boolean',
        'opration'=>'string'
    ];

    protected $guarded = [];
    //单独模型事件retrieved、creating、created、updating、updated、saving、saved、deleting、deleted、restoring、restored
    /*protected $dispatchesEvents = [
        'saved' => LogSaved::class,
        'deleted' => LogDeleted::class,
    ];*/
    public static $methodColors = [
        'GET'    => 'green',
        'POST'   => 'yellow',
        'PUT'    => 'blue',
        'DELETE' => 'red',
    ];

    public static $methods = [
        'GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'PATCH',
        'LINK', 'UNLINK', 'COPY', 'HEAD', 'PURGE',
    ];

    /**
     * 本地作用域
     * 限制查询只包括受欢迎的用户。
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function scopeId($query)
    {
        return $query->where('id', '>', 10);
    }

    /**
     * 模型的「启动」方法
     *
     * @return void
     */
    protected static function boot()
    {
        //全局条件
        parent::boot();
        /*static::addGlobalScope('id', function(Builder $builder) {
            $builder->where('id', '>=', 0);
        });*/
        static::observe(LogObserver::class);
    }


}
